<template>
  <!-- 留言板  -->
  <div id="messageboard">
    <div class="title-img pad-l10"><img src="../../../static/images/icon/liuyan.svg" alt="">留言板</div>
    <div class="course">
<!--      <el-form :rules="rules" ref="ruleForm" :model="ruleForm">-->
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="180px" class="demo-ruleForm">
        <el-form-item label="姓名" >
          <el-input v-model="ruleForm.userName"></el-input>
        </el-form-item>
<!--        <el-form-item label="电话（方便我们联系）" required prop="userPhone">-->
        <el-form-item label="电话（方便我们联系）">
          <el-input v-model="ruleForm.userPhone"></el-input>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="ruleForm.userEmail"></el-input>
        </el-form-item>
        <el-form-item label="留言内容">
          <el-input type="textarea" v-model="ruleForm.content" style="width: 208px"></el-input>
        </el-form-item>
        <el-form-item class="center">
          <el-button type="primary" @click="submitForm">提交</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import Sticky from '@/components/Sticky'
import service from '../../utils/request'

export default {
  name: 'MessageBoard',
  data () {
    return {
      pageMinHeight: 0,
      ruleForm: {
        userName: '',
        userPhone: '',
        content: '',
        userEmail: ''
      },
      rules: {
        userName: [
          {required: true, message: '请输入姓名', trigger: 'blur'},
        ],
        userPhone: [
          {required: true, message: '请输入电话', trigger: 'blur'},
        ],
        content: [
          {required: true, message: '请填写留言内容或建议', trigger: 'blur'}
        ]
      },
      url:{
        message:'/sunMessage/add'
      }
    }
  },
  watch: {},
  computed: {},
  components: {
    Sticky
  },
  created () {
  },
  mounted () {
    // 屏幕的高度
    this.pageMinHeight = window.innerHeight - 62
  },
  methods: {
    submitForm (formName) {
      //添加一条记录
      service.post(this.url.message,this.ruleForm).then(res=>{
        if (res.data.success){
          this.$message({
            message: '留言成功，我们会尽快回复',
            type: 'success'
          });
          this.resetForm()
        }
      }).catch(error=>{
        console.log(error)
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
      this.ruleForm = {}
    },
  }
}
</script>
<style>

</style>
